import { post } from '@/utils/request';
import * as api from '@/constants/api';

export default {
  namespace: 'log',

  state: {
    rows: [],
    pagination: {},
  },

  effects: {
    * fetchList({ payload }, { call, put }) {
      const res = yield call(() => post(api.LOG_LIST, payload));

      yield put({
        type: 'saveList',
        payload: res,
      });
    },
  },

  reducers: {
    saveList(state, action) {
      return {
        ...state,
        rows: action.payload.rows,
        pagination: {
          ...state.pagination,
          total: action.payload.total,
          pageSize: action.payload.pageSize,
          current: action.payload.pageNo,
        },
      };
    },
  },
};
